# -*- coding: utf-8 -*-
"""
@Time ： 2020/9/21 17:16
@Auth ： Mr. JJ_Cloud
@Company ：testingedu.com.cn
@Function ：练习0922
"""

import os
import requests

class FileDownloader(): #类名
    def __init__(self,url): #类的初始化
        self.url = url

    def download_file(self):
        s = requests.get(self.url)
        file_name = self.url.split("/")[-1]
        with open(file_name,"wb") as hf:
            hf.write(s.content)
        file_path = os.path.abspath(file_name)
        print("file downloaded to %s" % file_path)
        return file_path  # 有返回值，返回下载后的保存路径
if __name__== "__main__":
    fd_obj =  FileDownloader("https://www.zipython.com/download/angel.mp3")
    # FileDownloader类初始化，成fd_obj对象
    fd_obj.download_file() #一般对象才能调用方法（函数)


